package com.fyzk.betzhushu.klsf;

import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.betzhushu.ZhuShuBase;

import java.math.BigInteger;
import java.util.List;

/**
 * Created by miao on 2016/12/20
 * 快乐十分胆拖玩法注数
 */

public class KLSFSelNumDuplexZhushu extends ZhuShuBase {

    private int maxDan = 1;
    public KLSFSelNumDuplexZhushu(int maxDan) {
        this.maxDan = maxDan;
    }

    @Override
    public long betZhuShu(List<List<BallInfo>> balls) {
        int dan = 0;
        int hong = 0;

        for (int i = 0; i < balls.size(); i++) {
            List<BallInfo> infos = balls.get(i);
            int selectedNum = 0;
            for (int j = 0; j < infos.size(); j++) {
                BallInfo info = infos.get(j);
                if (info.isSelected()) {
                    selectedNum++;
                }
            }
            switch (i) {
                case 0:
                    dan = selectedNum;
                    break;
                case 1:
                    hong = selectedNum;
                    break;
                default:
                    break;
            }
        }

        return getZhuShu_Dan(dan, hong);
    }

    /**
     * 计算胆拖注数
     */
    private long getZhuShu_Dan(int dan, int hong){
//		if ((dan + hong) == (maxDan + 1)) {
//			return 1;
//		}
        if (dan > 0 && dan < (maxDan + 1) && hong >= 1 && (dan + hong) > maxDan) {
            BigInteger big = c_x_y(hong).divide(c_x_y((maxDan + 1) - dan)).divide(c_x_y(hong - ((maxDan + 1) - dan)));
            return  big.longValue();
        }else{
            return 0;
        }
    }

    private BigInteger c_x_y(int n){
        BigInteger big = new BigInteger(""+n);

        return (n == 0) ? new BigInteger("1") : big.multiply(c_x_y(n - 1)) ;
    }
}
